<!-- include tpl=head menutitle=网站首页 title=取回密码 -->
<script type="text/javascript">
function login_reset_pass()
{
	$("#getpass-form").ajaxSubmit({
		url:api_url('login','repass'),
		type:'post',
		dataType:'json',
		success:function(rs){
			if(rs.status){
				$.dialog.alert('密码修改成功，请登录',function(){
					$.phpok.go(get_url('login'));
					return true;
				},'succeed');
				return true;
			}
			if(!rs.info){
				rs.info = '获取失败，请联系管理员。';
			}
			$.dialog.alert(rs.info);
			return false;
		}
	});
	return false;
}
function update_type(val)
{
	var url = get_url('login','getpass','type_id='+val);
	$.phpok.go(url);
}
</script>
<!-- if $type_id == 'email' -->
<script type="text/javascript">
var maxtime = 300;
var email_send_lock = false;
var win_time_out;
function update_send_email_loading()
{
	maxtime--;
	if(maxtime < 1){
		$("#email_send_status").val('发送邮件验证码');
		email_send_lock = false;
		maxtime = 300;
		window.clearInterval(win_time_out);
		return true;
	}
	var tips = "验证码已发送("+maxtime+")";
	$("#email_send_status").val(tips);
}

function send_email()
{
	if(email_send_lock){
		$.dialog.alert('验证码已发送，请五分钟后再执行');
		return false;
	}
	var url = api_url('vcode','email');
	var email = $("#email").val();
	if(!email){
		$.dialog.alert('邮箱不能为空');
		return false;
	}
	url += "&email="+$.str.encode(email);
	$.dialog.tips("请稍候…");
	update_send_email_loading();
	$.phpok.json(url,function(rs){
		if(rs.status){
			maxtime = 300;
			email_send_lock = true;
			
			win_time_out = window.setInterval("update_send_email_loading()",1000);
			return true;
		}
		$.dialog.alert(rs.info);
		$("#email_send_status").val('发送邮件验证码');
		return false;
	})
}
</script>
<!-- /if -->
<!-- if $type_id == 'sms' -->
<script type="text/javascript">
var maxtime = 60;
var mobile_send_lock = false;
var win_time_out;
function update_send_sms_loading()
{
	maxtime--;
	if(maxtime < 1){
		$("#mobile_send_status").val('发送手机验证码');
		mobile_send_lock = false;
		maxtime = 60;
		window.clearInterval(win_time_out);
		return true;
	}
	var tips = "验证码已发送("+maxtime+")";
	$("#mobile_send_status").val(tips);
}

function send_sms()
{
	if(mobile_send_lock){
		$.dialog.alert('验证码已发送，请一分钟后再执行');
		return false;
	}
	var url = api_url('vcode','sms');
	var mobile = $("#mobile").val();
	if(!mobile){
		$.dialog.alert('手机号不能为空');
		return false;
	}
	url += "&mobile="+mobile;
	$.dialog.tips("请稍候…");
	update_send_sms_loading();
	$.phpok.json(url,function(rs){
		if(rs.status){
			maxtime = 60;
			mobile_send_lock = true;
			win_time_out = window.setInterval("update_send_sms_loading()",1000);
		}else{
			$.dialog.alert(rs.info);
			$("#mobile_send_status").val('发送手机验证码');
		}
	})
}
</script>
<!-- /if -->
<section class="container">
<div class="p-4 m-4">
	<form class="am-form" id="getpass-form" method="post" onsubmit="return login_reset_pass()">
		<h3>取回密码操作</h3>
		<div class="form-group">
			<label for="mobile">选择密码取回方式</label>
			<select id="type_id" name="type_id" class="form-control" onchange="update_type(this.value)">
				<!-- if $check_email --><option value="email"{if $type_id == 'email'} selected{/if}>邮件验证码</option><!-- /if -->
				<!-- if $check_sms --><option value="sms"{if $type_id == 'sms'} selected{/if}>短信验证码</option><!-- /if -->
			</select>
		</div>
		<!-- if $type_id == 'email' -->
		<div class="form-group">
			<label for="mobile">邮箱 Email</label>
			<div class="row">
				<div class="col-sm-6"><input type="text" id="email" class="form-control" name="email" placeholder="请输入邮箱" /></div>
				<div class="col-sm-5"><input type="button" value="发送邮件验证码" onclick="send_email()" class="btn btn-primary" id="email_send_status" /></div>
			</div>
		</div>
		<div class="form-group">
			<label for="_chkcode">邮件验证码</label>
			<input type="text" name="_chkcode" class="form-control" id="_chkcode" placeholder="请输入邮箱收到的验证码" />
		</div>
		<!-- /if -->
		<!-- if $type_id == 'sms' -->
		<div class="form-group">
			<label for="mobile">手机号</label>
			<div class="am-g am-g-collapse">
				<div class="col-sm-6"><input type="text" id="mobile" class="form-control" name="mobile" placeholder="请输入手机号" /></div>
				<div class="col-sm-1"></div>
				<div class="col-sm-5"><input type="button" class="form-control" value="发送手机验证码" onclick="send_sms()" class="btn btn-primary" id="mobile_send_status" /></div>
			</div>
		</div>
		<div class="form-group">
			<label for="_chkcode">手机验证码</label>
			<input type="text" name="_chkcode" id="_chkcode" class="form-control" placeholder="请输入手机上收到的验证码" />
		</div>
		<!-- /if -->
		<div class="form-group">
			<label for="_chkcode">新密码</label>
			<input type="password" name="newpass" id="newpass" class="form-control" placeholder="请输入新密码" />
		</div>
		<div class="form-group">
			<label for="_chkcode">确认密码</label>
			<input type="password" name="chkpass" id="chkpass" class="form-control" placeholder="请再次输入新密码" />
		</div>
		<div class="row">
			<div class="col">
				<button type="submit" class="btn btn-primary" id="login_submit">修改密码</button>
			</div>
			<div class="col text-right">
				<a href="{$sys.url}">返回首页</a>
			</div>
		</div>
	</form>
</div>
</section>
<!-- include tpl=foot -->